package com.ymatou.promotion.api.testcase;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.promotion.api.parameter.CouponBatchBean;
import com.ymatou.promotion.api.parameter.CouponValueInfoBean;
import com.ymatou.promotion.api.parameter.CreateSellerCouponBean;
import com.ymatou.promotion.api.service.CreateSellerCouponCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.YmtCouponBatch;
import com.ymttest.database.model.YmtCouponScenario;
import com.ymttest.database.model.YmtCouponSetting;
import com.ymttest.database.model.YmtCouponValue;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.database.sqlwapper.YmtCouponScenarioWapper;
import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
import com.ymttest.database.sqlwapper.YmtCouponValueWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/**
 * 创建商家优惠券接口
 *
 * @author chenjiazhu
 */
@TestSuite
public class Ts_CreateSellerCoupon {
	private static CreateSellerCouponBean createsellercouponBean;
	private static CreateSellerCouponCall createsellercouponCall;

	private static CouponBatchBean couponBatchBean = new CouponBatchBean();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建商家优惠券接口");
	}

	@Before
	public void caseUp() {
		createsellercouponBean = new CreateSellerCouponBean();
		createsellercouponCall = new CreateSellerCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createsellercouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_001() {
		Logger.start(true, "创建满减优惠券");
		try {

			String name = "CouponName_满减优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/**
	 * 返红包的业务已经不存在了，所以开发代码中强制设置CouponUseType = 1,
	 */
	@Ignore
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_002() {
		Logger.start(true, "创建返红包优惠券");
		try {
			String name = "CouponName_返红包优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.getCouponValues().removeAll(
					couponBatchBean.getCouponValues());

			CouponValueInfoBean couponValue = new CouponValueInfoBean();

			couponValue.setOrderValue(new BigDecimal(100));
			couponValue.setCouponValue(new BigDecimal(100));
			couponValue.setCouponUseType(2);

			couponBatchBean.getCouponValues().add(couponValue);

			couponBatchBean.setCouponValues(couponBatchBean.getCouponValues());

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_003() {
		Logger.start(true, "创建全场优惠券");
		try {
			String name = "CouponName_全场优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_004() {
		Logger.start(true, "创建商品优惠券");
		try {
			String name = "CouponName_商品优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setScenarioType(2);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_005() {
		Logger.start(true, "创建洋码头PC端平台优惠券");
		try {
			String name = "CouponName_洋码头PC端优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setUsePlatforms("1");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_006() {
		Logger.start(true, "创建洋码头WAP端平台优惠券");
		try {
			String name = "CouponName_洋码头WAP端优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setUsePlatforms("2");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);

			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_007() {
		Logger.start(true, "创建洋码头APP平台优惠券");
		try {
			String name = "CouponName_洋码头APP优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setUsePlatforms("3");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_008() {
		Logger.start(true, "创建神器APP平台优惠券");
		try {
			String name = "CouponName_神器APP优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setUsePlatforms("4");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_009() {
		Logger.start(true, "创建神器WAP平台优惠券");
		try {
			String name = "CouponName_神器WAP优惠券";
			String desc = "CouponDesc_神器WAP优惠券_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setUsePlatforms("5");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_010() {
		Logger.start(true, "创建洋码头PC端商品优惠券");
		try {
			String name = "CouponName_洋码头PC端商品优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setScenarioType(2);
			couponBatchBean.setUsePlatforms("1");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_011() {
		Logger.start(true, "创建洋码头WAP端商品优惠券");
		try {
			String name = "CouponName_洋码头WAP端商品优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setScenarioType(2);
			couponBatchBean.setUsePlatforms("2");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_012() {
		Logger.start(true, "创建洋码头APP商品优惠券");
		try {
			String name = "CouponName_洋码头APP商品优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setScenarioType(2);
			couponBatchBean.setUsePlatforms("3");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_013() {
		Logger.start(true, "创建神器APP商品优惠券");
		try {
			String name = "CouponName_神器APP商品优惠券";
			String desc = "CouponDesc_" + TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setScenarioType(2);
			couponBatchBean.setUsePlatforms("4");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateSellerCoupon_014() {
		Logger.start(true, "创建神器WAP商品优惠券");
		try {
			String name = "CouponName_神器WAP商品优惠券";
			String desc = "CouponDesc_神器WAP优惠券_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setScenarioType(2);
			couponBatchBean.setUsePlatforms("5");

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			VerifyReturnDataBase();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_015() {
		Logger.start(false, "验证优惠券名称空时报错");
		try {
			String desc = "CouponDesc_验证优惠券名称不能为空"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(null, desc);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-1", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("优惠券名称不能为空", createsellercouponCall.getMsg(),
					"验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/**
	 * 与契约不同意，需要开发修改
	 */
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_016() {
		Logger.start(false, "验证优惠券说明空时返回报错");
		try {
			String name = "CouponName_优惠券说明不能为空";

			setDefaultCreateSellerCouponBean(name, null);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("200", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("0", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("创建商家优惠券成功",
					createsellercouponCall.getMessageText(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_017() {
		Logger.start(false, "验证优惠券未设置时返回报错");
		try {
			String name = "CouponName_优惠券面值未设置未设置";
			String desc = "CouponDesc_优惠券面值未设置未设置_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.getCouponValues().removeAll(
					couponBatchBean.getCouponValues());

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-3", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("优惠券面值未设置", createsellercouponCall.getMsg(),
					"验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_018() {
		Logger.start(false, "验证订单金额小于优惠券面值时返回报错");
		try {
			String name = "CouponName_订单金额必须大于优惠券面值";
			String desc = "CouponDesc_订单金额必须大于优惠券面值_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			// OrderValue：订单金额
			couponBatchBean.getCouponValues().get(0)
					.setOrderValue(new BigDecimal(10));
			// CouponValue：优惠券面值
			couponBatchBean.getCouponValues().get(0)
					.setCouponValue(new BigDecimal(100));

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-4", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("订单金额[10]必须>优惠券面值[100]",
					createsellercouponCall.getMsg(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_019() {
		Logger.start(false, "验证最大发放数量小于0时返回报错");
		try {
			String name = "CouponName_最大发放数量必须大于0";
			String desc = "CouponDesc_最大发放数量必须大于0_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setMaxSendNum(-10);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-5", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("最大发放数量必须>0", createsellercouponCall.getMsg(),
					"验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_020() {
		Logger.start(false, "验证用户最大领取数量小于0时返回报错");
		try {
			String name = "CouponName_用户最大领取数量必须大于0";
			String desc = "CouponDesc_用户最大领取数量必须大于0_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setUserMaxReceiveNum(-1);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-6", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("用户最大领取数量必须>0",
					createsellercouponCall.getMsg(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_021() {
		Logger.start(false, "验证结束时间大于起始时间时返回报错");
		try {
			String name = "CouponName_验证结束时间必须>=起始时间";
			String desc = "CouponDesc_验证结束时间必须>=起始时间_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();
			Date dAfter = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, 1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			Calendar calendar2 = Calendar.getInstance(); // 得到日历
			calendar2.setTime(dNow);// 把当前时间赋给日历
			calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
			dAfter = calendar2.getTime(); // 得到前一天的时间

			couponBatchBean.setValidStart(dBefore);
			couponBatchBean.setValidEnd(dAfter);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-7", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("有效期结束时间必须>=起始时间",
					createsellercouponCall.getMsg(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_022() {
		Logger.start(false, "验证最大发放数量小于用户最大领取数量时返回报错");
		try {
			String name = "CouponName_验证最大发放数量必须>=用户最大领取数量";
			String desc = "CouponDesc_验证最大发放数量必须>=用户最大领取数量_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.setMaxSendNum(10);
			couponBatchBean.setUserMaxReceiveNum(100);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-8", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("最大发放数量必须>=用户最大领取数量",
					createsellercouponCall.getMsg(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_023() {
		Logger.start(false, "验证优惠券面值小于0时返回报错");
		try {
			String name = "CouponName_优惠券面值必须大于0";
			String desc = "CouponDesc_优惠券面值必须大于0_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.getCouponValues().get(0)
					.setCouponValue(new BigDecimal(0));

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-10", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("优惠券面值必须>0", createsellercouponCall.getMsg(),
					"验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_024() {
		Logger.start(false, "验证订单金额未设置时返回报错");
		try {
			String name = "CouponName_订单金额未设置";
			String desc = "CouponDesc_订单金额未设置_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.getCouponValues().removeAll(
					couponBatchBean.getCouponValues());

			CouponValueInfoBean couponValue = new CouponValueInfoBean();

			couponValue.setCouponValue(new BigDecimal(10));
			couponValue.setCouponUseType(1);

			couponBatchBean.getCouponValues().add(couponValue);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-9", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("订单金额必须>0", createsellercouponCall.getMsg(),
					"验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_025() {
		Logger.start(false, "验证优惠券面值未设置时返回报错");
		try {
			String name = "CouponName_优惠券面值未设置";
			String desc = "CouponDesc_优惠券面值未设置_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			couponBatchBean.getCouponValues().removeAll(
					couponBatchBean.getCouponValues());

			CouponValueInfoBean couponValue = new CouponValueInfoBean();

			couponValue.setOrderValue(new BigDecimal(1000));
			couponValue.setCouponUseType(1);

			couponBatchBean.getCouponValues().add(couponValue);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("201", createsellercouponCall.getCode(),
					"验证返回Code");
			Logger.verifyEquals("-10", createsellercouponCall.getBCode(),
					"验证返回BCode");
			Logger.verifyEquals("优惠券面值必须>0", createsellercouponCall.getMsg(),
					"验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/**
	 * CouponValues发过去三条，只插入了前两条，需要开发看下
	 */
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CreateSellerCoupon_026() {
		Logger.start(true, "创建多面值优惠券");
		try {
			String name = "CouponName_神器WAP优惠券";
			String desc = "CouponDesc_神器WAP优惠券_"
					+ TestDataManager.getRandomNum(10);

			setDefaultCreateSellerCouponBean(name, desc);

			CouponValueInfoBean couponValue2 = new CouponValueInfoBean();

			couponValue2.setOrderValue(new BigDecimal(200));
			couponValue2.setCouponValue(new BigDecimal(20));
			couponValue2.setCouponUseType(1);

			CouponValueInfoBean couponValue3 = new CouponValueInfoBean();

			couponValue3.setOrderValue(new BigDecimal(300));
			couponValue3.setCouponValue(new BigDecimal(30));
			couponValue3.setCouponUseType(1);

			couponBatchBean.getCouponValues().add(couponValue2);
			couponBatchBean.getCouponValues().add(couponValue3);

			createsellercouponBean.setCouponBatchBean(couponBatchBean);
			createsellercouponCall.setData(createsellercouponBean);
			createsellercouponCall.callService();

			// 验证返回
			Logger.verifyEquals("200", createsellercouponCall.getCode(), "验证返回");
			Logger.verifyEquals("创建商家优惠券成功",
					createsellercouponCall.getMessageText(), "验证返回");

			// 验证Ymt_CouponBatch表
			String sBatchCode = createsellercouponCall.getBatchCode();
			List<YmtCouponBatch> list = new YmtCouponBatchWapper()
					.selectBysBatchCode(sBatchCode);

			Logger.verifyEquals(1, list.size(),
					"YmtCouponBatch表生成多条sBatchCode=" + sBatchCode + "的数据。");

			if (list.size() >= 1) {
				YmtCouponBatch item = list.get(0);
				Logger.verifyEquals(couponBatchBean.getCouponName(),
						item.getsCouponName(), "数据库中sCouponName不正确");
				Logger.verifyEquals(couponBatchBean.getSellerId(),
						item.getiOperatorId(), "数据库中iOperatorId不正确");
				Logger.verifyEquals(couponBatchBean.getMaxSendNum(),
						item.getiCouponTotalNum(), "数据库中iCouponTotalNum不正确");
				Logger.verifyEquals(couponBatchBean.getUserMaxReceiveNum(),
						item.getiCouponNumPerUser(), "数据库中iCouponNumPerUser不正确");

				// 验证Ymt_CouponSetting表
				List<YmtCouponSetting> settinglist = new YmtCouponSettingWapper()
						.selectByiCouponSettingId(item.getiCouponSettingId());

				Logger.verifyEquals(1, settinglist.size(),
						"YmtCouponSetting表生成条数不对应。");

				if (settinglist.size() >= 1) {
					YmtCouponSetting settingItem = settinglist.get(0);
					Logger.verifyEquals(couponBatchBean.getScenarioType(),
							settingItem.getiScenarioType(),
							"数据库中ScenarioType不正确");
					Logger.verifyEquals(((CouponValueInfoBean) couponBatchBean
							.getCouponValues().get(0)).getCouponUseType(),
							settingItem.getiCouponUseType(),
							"数据库中iCouponUseType不正确");

					SimpleDateFormat formatter = new SimpleDateFormat(
							"yyyy-MM-dd HH:mm:ss");
					Logger.verifyEquals(
							formatter.format(couponBatchBean.getValidStart()),
							formatter.format(settingItem.getdValidStart()),
							"数据库中dValidStart不正确");

					SimpleDateFormat formatter2 = new SimpleDateFormat(
							"yyyy-MM-dd");
					Date endDate = formatter.parse(formatter2
							.format(couponBatchBean.getValidEnd())
							+ " 23:59:59");
					Logger.verifyEquals(formatter.format(endDate),
							formatter.format(settingItem.getdValidEnd()),
							"数据库中dValidEnd不正确");

					// 验证Ymt_CouponScenario表
					List<YmtCouponScenario> scenariolist = new YmtCouponScenarioWapper()
							.selectByiCouponScenarioId(settingItem
									.getiScenarioId());
					if (scenariolist.size() >= 1) {
						YmtCouponScenario scenarioItem = scenariolist.get(0);
						Logger.verifyEquals(((Integer) couponBatchBean
								.getSellerId()).toString(), scenarioItem
								.getSsellerids(), "数据库中Ssellerid不正确");
						Logger.verifyEquals(couponBatchBean.getUsePlatforms(),
								scenarioItem.getSuseplatforms(),
								"数据库中Suseplatforms不正确");
					}

					// 验证Ymt_CouponValue表
					List<YmtCouponValue> valuelist = new YmtCouponValueWapper()
							.selectByiCouponSettingId(settingItem
									.getiCouponSettingId());
					for (int i = 0; i < valuelist.size(); i++) {
						YmtCouponValue valueItem = valuelist.get(i);
						Logger.verifyEquals(
								((CouponValueInfoBean) couponBatchBean
										.getCouponValues().get(i))
										.getCouponValue(), new BigDecimal(
										valueItem.getFcouponvalue()
												.floatValue()),
								"数据库中Fcouponvalue不正确");
						Logger.verifyEquals(
								((CouponValueInfoBean) couponBatchBean
										.getCouponValues().get(i))
										.getOrderValue(), new BigDecimal(
										valueItem.getFminordervalue()
												.floatValue()),
								"数据库中Fminordervalue不正确");
					}

				}

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	public void setDefaultCreateSellerCouponBean(String couponName,
			String couponDesc) {
		int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

		couponBatchBean.setSellerId(sellerId);
		couponBatchBean.setCouponName(couponName);

		List<CouponValueInfoBean> couponValues = new ArrayList<CouponValueInfoBean>();

		CouponValueInfoBean couponValue = new CouponValueInfoBean();

		couponValue.setOrderValue(new BigDecimal(100));
		couponValue.setCouponValue(new BigDecimal(10));
		couponValue.setCouponUseType(1);

		couponValues.add(couponValue);

		couponBatchBean.setCouponValues(couponValues);
		couponBatchBean.setMaxSendNum(2000);
		couponBatchBean.setUserMaxReceiveNum(1);

		Date dNow = new Date(); // 当前时间
		Date dBefore = new Date();
		Date dAfter = new Date();

		Calendar calendar1 = Calendar.getInstance(); // 得到日历
		calendar1.setTime(dNow);// 把当前时间赋给日历
		calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
		dBefore = calendar1.getTime(); // 得到前一天的时间

		Calendar calendar2 = Calendar.getInstance(); // 得到日历
		calendar2.setTime(dNow);// 把当前时间赋给日历
		calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
		dAfter = calendar2.getTime(); // 得到前一天的时间

		couponBatchBean.setValidStart(dBefore);
		couponBatchBean.setValidEnd(dAfter);

		couponBatchBean.setScenarioType(1);
	}

	public void VerifyReturnDataBase() throws ParseException {
		// 验证返回
		Logger.verifyEquals("200", createsellercouponCall.getCode(), "验证返回Code");
		Logger.verifyEquals("创建商家优惠券成功",
				createsellercouponCall.getMessageText(), "验证返回MessageText");

		// 验证Ymt_CouponBatch表
		String sBatchCode = createsellercouponCall.getBatchCode();
		List<YmtCouponBatch> list = new YmtCouponBatchWapper()
				.selectBysBatchCode(sBatchCode);

		Logger.verifyEquals(1, list.size(), "验证Ymt_CouponBatch表生成sBatchCode="
				+ sBatchCode + "的条数。");

		if (list.size() >= 1) {
			YmtCouponBatch item = list.get(0);
			Logger.verifyEquals(couponBatchBean.getCouponName(),
					item.getsCouponName(), "验证数据库Ymt_CouponBatch表中sBatchCode="
							+ sBatchCode + "的记录中sCouponName");
			Logger.verifyEquals(couponBatchBean.getSellerId(),
					item.getiOperatorId(), "验证数据库Ymt_CouponBatch表中sBatchCode="
							+ sBatchCode + "的记录中iOperatorId");
			Logger.verifyEquals(couponBatchBean.getMaxSendNum(),
					item.getiCouponTotalNum(),
					"验证数据库Ymt_CouponBatch表中sBatchCode=" + sBatchCode
							+ "的记录中iCouponTotalNum");
			Logger.verifyEquals(couponBatchBean.getUserMaxReceiveNum(),
					item.getiCouponNumPerUser(),
					"验证数据库Ymt_CouponBatch表中sBatchCode=" + sBatchCode
							+ "的记录中iCouponNumPerUser");

			// 验证Ymt_CouponSetting表
			List<YmtCouponSetting> settinglist = new YmtCouponSettingWapper()
					.selectByiCouponSettingId(item.getiCouponSettingId());

			Logger.verifyEquals(
					1,
					settinglist.size(),
					"验证Ymt_CouponSetting表生成iCouponSettingId="
							+ item.getiCouponSettingId() + "条数正确");

			if (settinglist.size() >= 1) {
				YmtCouponSetting settingItem = settinglist.get(0);
				Logger.verifyEquals(
						couponBatchBean.getScenarioType(),
						settingItem.getiScenarioType(),
						"验证数据库Ymt_CouponSetting表中iCouponSettingId="
								+ item.getiCouponSettingId()
								+ "的记录中ScenarioType");
				Logger.verifyEquals(
						((CouponValueInfoBean) couponBatchBean
								.getCouponValues().get(0)).getCouponUseType(),
						settingItem.getiCouponUseType(),
						"验证数据库Ymt_CouponSetting表中iCouponSettingId="
								+ item.getiCouponSettingId()
								+ "的记录中iCouponUseType");

				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				Logger.verifyEquals(
						formatter.format(couponBatchBean.getValidStart()),
						formatter.format(settingItem.getdValidStart()),
						"验证数据库Ymt_CouponSetting表中iCouponSettingId="
								+ item.getiCouponSettingId()
								+ "的记录中dValidStart");

				SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd");
				Date endDate = formatter.parse(formatter2
						.format(couponBatchBean.getValidEnd()) + " 23:59:59");
				Logger.verifyEquals(
						formatter.format(endDate),
						formatter.format(settingItem.getdValidEnd()),
						"验证数据库Ymt_CouponSetting表中iCouponSettingId="
								+ item.getiCouponSettingId() + "的记录中dValidEnd");

				// 验证Ymt_CouponScenario表
				List<YmtCouponScenario> scenariolist = new YmtCouponScenarioWapper()
						.selectByiCouponScenarioId(settingItem.getiScenarioId());

				Logger.verifyEquals(1, scenariolist.size(),
						"验证Ymt_CouponScenario表生成iCouponScenarioId="
								+ settingItem.getiScenarioId() + "条数正确");

				if (scenariolist.size() >= 1) {
					YmtCouponScenario scenarioItem = scenariolist.get(0);
					Logger.verifyEquals(((Integer) couponBatchBean
							.getSellerId()).toString(), scenarioItem
							.getSsellerids(),
							"验证数据库Ymt_CouponScenario表中iCouponScenarioId="
									+ settingItem.getiScenarioId()
									+ "的记录中的Ssellerid");
					Logger.verifyEquals(couponBatchBean.getUsePlatforms(),
							scenarioItem.getSuseplatforms(),
							"验证数据库Ymt_CouponScenario表中iCouponScenarioId="
									+ settingItem.getiScenarioId()
									+ "的记录中的Suseplatforms");
				}

				// 验证Ymt_CouponValue表
				List<YmtCouponValue> valuelist = new YmtCouponValueWapper()
						.selectByiCouponSettingId(settingItem
								.getiCouponSettingId());

				Logger.verifyEquals(
						1,
						valuelist.size(),
						"验证Ymt_CouponValue表生成iCouponSettingId="
								+ settingItem.getiCouponSettingId() + "条数正确");

				if (valuelist.size() >= 1) {
					YmtCouponValue valueItem = valuelist.get(0);
					Logger.verifyEquals(((CouponValueInfoBean) couponBatchBean
							.getCouponValues().get(0)).getCouponValue(),
							new BigDecimal(valueItem.getFcouponvalue()
									.floatValue()),
							"验证数据库Ymt_CouponValue表中iCouponSettingId="
									+ settingItem.getiCouponSettingId()
									+ "的记录中的Fcouponvalue");
					Logger.verifyEquals(((CouponValueInfoBean) couponBatchBean
							.getCouponValues().get(0)).getOrderValue(),
							new BigDecimal(valueItem.getFminordervalue()
									.floatValue()),
							"验证数据库Ymt_CouponValue表中iCouponSettingId="
									+ settingItem.getiCouponSettingId()
									+ "的记录中的Fminordervalue");
				}

			}

		}

	}
}